//
//  OrderProductListController.m
//  zhijianshejian
//
//  Created by admin on 16/5/27.
//  Copyright © 2016年 haoniu-duhuan. All rights reserved.
//

#import "OrderProductListController.h"
#import "OrderProductCell.h"

@interface OrderProductListController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation OrderProductListController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.title = @"商品清单";
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
//    UIBarButtonItem * left = [[UIBarButtonItem alloc]init];
//    [left setImage:[UIImage imageNamed:@"fanhui"]];
//    [left setTarget:self];
//    [left setAction:@selector(backPage)];
//    self.navigationItem.leftBarButtonItem = left;
    
    _tableView.dataSource =self;
    _tableView.delegate = self;
    [_tableView setBackgroundColor:[AppConfig colorWithHexString:@"#f5f5f5"]];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    
    
    NSLog(@"====datasource:%@",_dataSource);
    
    UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, 0.5)];
    lineLabel.backgroundColor = [UIColor grayColor];
    [self.view addSubview:lineLabel];
}
-(void)backPage{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma -mark TableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [_dataSource count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100.f;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary * dict = _dataSource[indexPath.row];
    static NSString * cellID = @"OrderProductCell";
    OrderProductCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[[NSBundle mainBundle]loadNibNamed:cellID owner:self options:nil] firstObject];
    }
    [cell setFrame:CGRectMake(0, 0, mainScreenSize.width, 100)];
    
    NSString * prodImg = [NSString stringWithFormat:@"%@%@",url_Base,[dict objectForKey:@"prodImg"]];
    [cell.headImage sd_setImageWithURL:[NSURL URLWithString:prodImg] placeholderImage:[UIImage imageNamed:@"shopping.png"]];
    [cell.headName setTextColor:[AppConfig colorWithHexString:@"#454545"]];
    [cell.headName setText:[NSString stringWithFormat:@"订单号:%@",[dict objectForKey:@"orderSn"]]];
//    [cell.headDetail setTextColor:[AppConfig colorWithHexString:@"#454545"]];
    [cell.headDetail setText:[NSString stringWithFormat:@"%@",[dict objectForKey:@"goodsName"]]];
    NSString * salePrice = [dict objectForKey:@"goodsPrice"];
//    salePrice = salePrice==nil?[dict objectForKey:@"salePrice"]:salePrice;
    [cell.price setText:[NSString stringWithFormat:@"¥ %0.2f",[salePrice floatValue]]];
    [cell.count setTextColor:[AppConfig colorWithHexString:@"#454545"]];
    [cell.count setText:[NSString stringWithFormat:@"x %@",[dict objectForKey:@"goodsNumber"]]];

    [cell.line setBackgroundColor:[AppConfig colorWithHexString:@"#f0f0f0"]];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    NSDictionary * pro = _dataSource[indexPath.row];
//    HNOrderProductDetailController * proDetail = [[HNOrderProductDetailController alloc]init];
//    [proDetail setGoodsId:[pro objectForKey:@"goodsId"]];
//    [self.navigationController pushViewController:proDetail animated:YES];
}



@end
